﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "UMG/GameOverWidget.h"

#include "Character/PlayerCharacter.h"
#include "Helper/DebugHelper.h"
#include "Kismet/GameplayStatics.h"

class APlayerCharacter;

bool UGameOverWidget::Initialize()
{
	if (!Super::Initialize())
	{
		return false;
	}
	RestartBtn->OnClicked.AddDynamic(this, &UGameOverWidget::RestartBtnFunc);
	BackBtn->OnClicked.AddDynamic(this, &UGameOverWidget::BackBtnFunc);
	return true;
}

void UGameOverWidget::RestartBtnFunc()
{
	UGameplayStatics::OpenLevel(GetWorld(),FName("SunTemple"));
	// player恢复操作
	APlayerCharacter* PlayerPawn = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
	if(PlayerPawn)
	{
		PlayerPawn->StartOperation();
	}
}

void UGameOverWidget::BackBtnFunc()
{
	APlayerCharacter* PlayerPawn = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
	if (PlayerPawn)
	{
		PlayerPawn->StopOperation();
	}
	UGameplayStatics::OpenLevel(GetWorld(),FName("StartMenu"));
}
